<?php
namespace app\index\controller;

use think\Request;
use think\Db;

class CopyController{
    public function getList(){
        



        $getdata = $_GET;
        $state = $_GET['state'];
        $where = 'state = '.$state;
        if(isset($getdata['uid']))
        {
            $where .= ' and uid = '.$_GET['uid'];
        }
        $list = Db::table('mreading')->where('state = '.$state)->order('mread_id desc')->limit(500)->select();
        
        return json($list);
    }

    public function getDetail(){
        $list = Db::table('mreading')
            ->where(['mread_id' => $_GET['mread_id']])
            ->select();

        return json($list);
    }

    public function accept()
    {
        $fault = $_GET['mread_number'];
//        $upArr = ;

        $data = Db::name('mreading')
            ->where("mread_number = '".$fault."' and state != 1")
            ->find();
        if($data)
        {
            $reData = array(
                'code'  => 201,
                'msg'   => '该工单已经被处理'
            );
            return json($reData);
        }

        $res = Db::name('mreading')
            ->where(['mread_number'=>$_GET['mread_number']])
            ->update(['uid'=>$_GET['uid'],'state'=>'2','gettime'=>date('Y-m-d H:i:s',time())]);
        if($res)
        {
            $reData = array(
                'code'  =>  200,
                'msg'   =>  '接单成功'
            );
        }

        return json($reData);
    }


     public function addProcess(Request $request)
    {
       
        $postData = $request->post();
        $con_number = $postData['mread_number'];
        $postData['feedbacktime'] = date('Y-m-d H:i:s',time());
        $postData['state']  =   3;
        unset($postData['mread_number']);

     
         $res = Db::name('mreading')->where(['mread_number'=>$con_number])->update($postData);

       

       if($res)
       {
            $reData = array(
                'code'  =>  200,
                'msg'   =>  '反馈成功'
            );
       }
        //dump($data);die;
        return json($reData);
    }
}